<?php
namespace app\business\controller;
use app\business\model\BusinessClassify;
use app\business\model\BusinessLogin;
use app\business\model\BusinessMenu;
use think\Controller;
use app\business\controller\Base;
use think\Session;
use think\Db;

class Comment extends Base
{
    public function index()
    {

        $username = Session::get('username');

        $count = BusinessLogin::where('username',$username)->find();

        $num=$count['business_id'];

        $data = Db::table('business_comment')->where('shop_id',$num)->select();

        $this->assign('data',$data);

        return $this->fetch();
    }

    public function delete($id)
    {
    	$static = db('business_comment')->where('id',$id)->delete();

    	if ($static) {
    		return $this->redirect('business/comment/index');
    	}else{
    		return $this->error('发生位置错误，请稍后重试！','business/comment/index');
    	}
    }

    public function reply($id)
    {
    	$data = Db::table('business_comment')
					->Field('c.id as cid,c.post_time as shangchuan,u.*,c.*,i.*')
					->alias('c')
					->join('business_users u','c.uid = u.id' ,'LEFT')
					->join('business_info i' ,'c.shop_id = i.id')
					->where('c.id','=',$id)
					->find();

    	$this->assign('data',$data);

    	return $this->fetch();
    }

    public function do_reply()
    {
    	$data['id'] = input('post.id');
    	$data['static'] = 2;
    	$data['comment_reply'] = input('post.comment_reply');
    	$static = db('business_comment')->update($data);

    	if ($static) {
    		return $this->success('回复成功！','business/comment/index');
    	}else{
    		return $this->error('发生未知错误，请稍后重试！');
    	}
    }

}